numpy indexing
Official documents
hr.icon
Tips
Numpy配列のAdvanced Indexingは知らないとわけわからなくなる。([], compare, condition, 条件式, fancy indexing ) - Qiita
MetPy Mondays '#90 - What is a NumPy Axis? : Unidata Developer's Blog
hr.icon
Examples
When f contains frequencies and P contains spectral density, the top 10 corresponding frequencies in descending order of 𝑃
code:python
range selection 1
code:python
import numpy as np
# lon: longitude lat:latittude
xrange=np.logical_and(lon>=120.,lon<=180.)
yrange=np.logical_and(lat>=20.,lat<=45.)
range selection 2
code:python
import numpy as np
# lon: longitude lat:latittude
xrange=((lon>136.) & (lon<140.))
yrange=((lat>36) & (lat<38))
range selection 3
code:python
import numpy as np
# lon: longitude lat:latittude
x=np.where(np.logical_and(lon>=120.,lon<=180.))0 y=np.where(np.logical_and(lat>=20.,lat<=30.))0 find nearest value in numpy array
code:python
import numpy as np
def find_nearest(array,value):
idx=(np.abs(array-value)).argmin()
find index where 2-dimensioal (multi-dimensional) array has maximum or minimum
code:python
ans=np.where(a == a.max())
i,j = np.unravel_index(a.argmax(), a.shape)
The index at which the array 'walk' first exceeds 10.
code:python
(np.abswalk>=10).argmax() NOT ~
code:python
a=np.arange(5)
Tips
...
code:python
hr.icon
Useful methods
argmax()
argmin()
searchsorted()
argsort()
argwhere()